package com.hzit.listener;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * 类名：
 * 作者：WF
 * 功能：监听applicatoin对象及对象的属性值的改变
 */
@WebListener
public class MyApplicationListener implements ServletContextListener, ServletContextAttributeListener {
	//1. 以下两个方法监听applcation对象本身的生命周期
	@Override
	public void contextInitialized(ServletContextEvent sce) {
		System.out.println("application创建完成。");
	}

	@Override
	public void contextDestroyed(ServletContextEvent sce) {
		System.out.println("application销毁完成。");
	}

	//2. 如下三个是监听application对象的属性值的变化
	@Override
	public void attributeAdded(ServletContextAttributeEvent event) {
		System.out.println("application对象添加属性。");
	}

	@Override
	public void attributeRemoved(ServletContextAttributeEvent event) {
		System.out.println("application对象移除属性。");
	}

	@Override
	public void attributeReplaced(ServletContextAttributeEvent event) {

	}

}
